import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;

import static javax.media.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW_MATRIX;

/**
 * Created by IntelliJ IDEA.
 * User: blakekl10
 * Date: 2/6/11
 * Time: 11:05 PM
 * To change this template use File | Settings | File Templates.
 */
public class Camera {
    private final float DEF_X = 0.0f;
    private final float DEF_Y = 0.0f;
    private final float DEF_DISTANCE = 10.0f;
    private final float CAMERA_Y = 1.0f;
    private float xRotate;
    private float yRotate;
    private float distance;
    private float[] currentMatrix = new float[16];

    Camera(){
        xRotate = 0.0f;
        yRotate = 0.0f;
        distance = 10.0f;
    }

    public void render(GL2 gl, GLU glu){
        glu.gluLookAt(0.0f, CAMERA_Y, distance, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
        gl.glRotatef(xRotate, 1.0f, 0.0f, 0.0f);
        gl.glRotatef(yRotate, 0.0f, 1.0f, 0.0f);
        gl.glGetFloatv(GL_MODELVIEW_MATRIX, currentMatrix, 0);
    }

    public float[] getCurrentMatrix (){
        return currentMatrix;
    }

    public float[] getBillboardMatrix(){
        return new float[] {
                currentMatrix[0], currentMatrix[4], currentMatrix[8], 0.0f,
                currentMatrix[1], currentMatrix[5], currentMatrix[9], 0.0f,
                currentMatrix[2], currentMatrix[6], currentMatrix[10], 0.0f,
                0.0f, 3.0f, -5.0f, 1.0f};
    }

    public float getCameraY(){
        return CAMERA_Y;
    }

    public float getxRotate() {
        return xRotate;
    }

    public void setxRotate(float xRotate) {
        this.xRotate = xRotate;
    }

    public float getyRotate() {
        return yRotate;
    }

    public void setyRotate(float yRotate) {
        this.yRotate = yRotate;
    }

    public float getDistance() {
        return distance;
    }

    public void setDistance(float distance) {
        this.distance = distance;
    }

    public void reset(){
        xRotate = DEF_X;
        yRotate = DEF_Y;
        distance = DEF_DISTANCE;
    }
}
